package top.ysh.springbootenable;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import;
import redis.clients.jedis.Jedis;
import top.ysh.config.MyImportBeanDefinitionRegistrar;
import top.ysh.config.MyImportSelector;
import top.ysh.config.UserConfig;
import top.ysh.domain.Role;
import top.ysh.domain.User;

import java.util.Map;


/**
 * Import的四种用法
 *  1. 导入Bean
 *  2. 导入配置类
 *  3. 导入ImportSelector的实现类
 *  4. 导入ImportBeanDefinitionRegistar
 */

// @SpringBootApplication
// @ComponentScan("top.ysh.config")
// @Import(UserConfig.class)

// @Import(User.class)
//     @Import(UserConfig.class)
//     @Import(MyImportSelector.class)
//     @Import({MyImportBeanDefinitionRegistrar.class})

@SpringBootApplication
public class SpringbootEnableApplication {

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(SpringbootEnableApplication.class, args);

/*
        // 获取Bean
        Object user = context.getBean("user");
        System.out.println(user);*/

        /*User bean = context.getBean(User.class);
        System.out.println(bean);*/

        /*Map<String, User> map = context.getBeansOfType(User.class);
        System.out.println(map);*/

        /*Role role = context.getBean(Role.class);
        System.out.println("role = " + role);*/

        Jedis jedis = context.getBean(Jedis.class);
        System.out.println("jedis = " + jedis);

        String hello = jedis.get("hello");
        System.out.println("hello = " + hello);
    }

    @Bean
    public Jedis jedis(){
        return new Jedis("192.168.23.129",6379);
    }

}
